<template>
	<view class="body">
		<view class="title-box" @click="back()">
			<!-- <view class="title">荷式拍卖列表</view> -->
			<text class="iconfont icon-left"></text>
		</view>
		<view class="item">
			<view class="title" style="display: flex;">
				用户名<span style="color: #D70000; display: block;">*</span>
			</view>
			<view class="in-ys">
				<input style="border: 0px;" placeholder="请输入用户名" border="none" v-model="userInfo.username" />
			</view>
		</view>
		<view class="item">
			<view class="title" style="display: flex;">
				邮箱<span style="color: #D70000; display: block;">*</span>
			</view>
			<view class="in-ys">
				<input style="border: 0px;" placeholder="请输入邮箱" border="none" v-model="userInfo.email" />
			</view>
		</view>
		<view class="item">
			<view class="title" style="display: flex;">
				电话<span style="color: #D70000; display: block;">*</span>
			</view>
			<view class="in-ys">
				<input style="border: 0px;" placeholder="请输入电话" border="none" v-model="userInfo.phone" />
			</view>
		</view>
		<view class="file">
			<uni-file-picker limit="1" title="请上传头像" @select="select" @progress="progress"
				@success="success"></uni-file-picker>
		</view>

		<view class="bottom">
			<view class="button" @click="submit">提交</view>
			<view class="button" @click="back">返回</view>
		</view>
	</view>
</template>

<script>
	import G from '@/config/global.js'
	import apis from '@/api/index.js'
	import {
		requestApi,
		uphttp
	} from '@/utils/request.js'
	// 导入公共组件方法
	import common from '@/common/js/common.js';
	export default {
		mixins: [common],
		data() {
			return {
				userInfo: {}
			}
		},
		onLoad() {
			this.userInfo = uni.getStorageSync("user");
		},
		methods: {
			// 获取上传状态
			select(e) {
				console.log('选择文件：', e)
				const url = e.tempFilePaths[0];
				uni.uploadFile({
					url: G.UPload,
					filePath: url,
					name: 'file',
					header: {
						'token':'Bearer ' + uni.getStorageSync("token"),
					},
					success: (res) => {
						console.log(res);
						if (res.statusCode == 200) {
						var result = JSON.parse(res.data)
						this.userInfo.icon = "/"+result.data.fileName
						
						console.log("result",result)
						console.log("this.userInfo.icon",this.userInfo.icon)
						
						}
					}
				});
			},
			// 获取上传进度
			progress(e) {
				console.log('上传进度：', e)
			},

			// 上传成功
			success(e) {
				console.log(e)
			},
			back() {
				uni.navigateBack({
					delta: 1
				})
			},
			submit() {
				console.log(this.userInfo);
				requestApi(apis.user.edit, this.userInfo, 'POST').then(res => {
					if (res.code == 200) {
						uni.setStorageSync("user", this.userInfo);
						this.back();
					}
				})

			}
		}
	}
</script>

<style>
	.body {
		padding: 0 32rpx;
		min-height: 100vh;
		background-image: url('../../static/bgc.png');
		background-size: 100% 100%;
		background-repeat: no-repeat;
	}

	.example-body {
		padding: 10px;
		padding-top: 0;
	}

	.img {
		width: 150rpx;
		height: 150rpx;
	}

	.item {
		display: flex;
		padding: 24rpx 0px;
		align-items: center;
		position: relative;
		/* justify-content: space-between; */
		border-bottom: 1px solid #fafafa;
	}

	.block {
		width: 100%;
		height: auto;
		border-bottom: 24rpx solid #F1F6FB;
		padding: 0 32rpx 32rpx;
		box-sizing: border-box;
		background-color: #FFFFFF;
	}

	.title {
		width: 160rpx;
		margin-right: 30rpx;
		font-family: 'PingFang SC';
		font-style: normal;
		font-weight: 400;
		font-size: 28rpx;
		line-height: 40rpx;
		color: rgba(51, 51, 51, 0.4);
		text-align: left;
	}

	.title1 {
		width: 160rpx;
		margin-right: 30rpx;
		font-family: 'PingFang SC';
		font-style: normal;
		font-weight: 400;
		font-size: 28rpx;
		line-height: 40rpx;
		color: rgba(51, 51, 51, 0.4);
		text-align: left;
		justify-content: space-between;
		position: absolute;
		top: -20rpx;
	}

	.in-ys {
		width: 80%;
		border-radius: 8rpx;
		background: #F6F6F6;
	}
	.file{
		display: flex;
		flex-direction: column;
		justify-content: center;
	}
	.button {

		width: 40%;

		color: #fff;
		background-color: #07b1ff;
		padding: 32rpx;
		border-radius: 64rpx;
		text-align: center;
	}

	.bottom {
		position: absolute;
		bottom: 40rpx;
		left: 50%;
		transform: translateX(-50%);
		width: 100%;
		display: flex;
		justify-content: space-between;
	}
</style>